layui.use('tree', function(){
    var data = [
        {
            title:"常住人口信息",
            id:"1",
            children:[
                {title:"信息主键编号"},
                {title:"人员编号"},
                {title:"姓名"},
                {title:"姓名汉语拼音"},
                {title:"外文姓"},
                {title:"外文名"},
                {title:"曾用名"},
                {title:"曾用名汉语拼音"},


            ]
        },
        {title:"常住人口注销信息",children:[

            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},
            {title:"外文姓"},


        ]},
        {title:"爆炸事故信息",children:[

            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},


        ]},
        {title:"涉爆案件收缴捡拾登记信息",children:[

            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},
            {title:"外文姓"},
            {title:"外文名"},
            {title:"曾用名"},
            {title:"曾用名汉语拼音"},
            {title:"别名/绰号"},
            {title:"别名/绰号汉语拼音"},
            {title:"性别代码"},
            {title:"出生日期"},
            {title:"身份证"},
            {title:"常用证件代码"},
            {title:"证件号码"},
            {title:"身高"},
            {title:"血型代码"}

        ]},
        {title:"涉爆案件的信息",children:[

            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},
            {title:"外文姓"},
            {title:"外文名"},
            {title:"曾用名"},
            {title:"曾用名汉语拼音"},
            {title:"别名/绰号"},
            {title:"别名/绰号汉语拼音"},
            {title:"性别代码"},
            {title:"出生日期"},
            {title:"身份证"},
            {title:"常用证件代码"},
            {title:"证件号码"},
            {title:"身高"},
            {title:"血型代码"}

        ]},
        {title:"涉爆案件单位信息",children:[
            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},
            {title:"外文姓"},
            {title:"外文名"},
            {title:"曾用名"},
            {title:"曾用名汉语拼音"},
            {title:"别名/绰号"},
            {title:"别名/绰号汉语拼音"},
            {title:"性别代码"},
            {title:"出生日期"},
            {title:"身份证"},
            {title:"常用证件代码"},
            {title:"证件号码"},
            {title:"身高"},
            {title:"血型代码"}

        ]},
        {title:"涉爆案件人员信息",children:[
            {title:"信息主键编号"},
            {title:"人员编号"},
            {title:"姓名"},
            {title:"姓名汉语拼音"},
            {title:"外文姓"},
            {title:"外文名"},
            {title:"曾用名"},
            {title:"曾用名汉语拼音"},
            {title:"别名/绰号"},
            {title:"别名/绰号汉语拼音"},
            {title:"性别代码"},
            {title:"出生日期"},
            {title:"身份证"},
            {title:"常用证件代码"},
            {title:"证件号码"},
            {title:"身高"},
            {title:"血型代码"}

        ]},
        {title:"涉爆物品地面站储存品种数量表"},
        {title:"涉爆物品购买证信息"},
        {title:"涉爆物品购买证物品信息"},
        {title:"涉爆物品运输证信息"},
        {title:"境外旅客住宿信息"}
    ];
    var tree = layui.tree;
    tree.render({
        elem: '#dataTree'
        ,data: data
        ,accordion: true
        ,edit: ['add', 'update', 'del']
        ,operate: function (obj) {
            var type = obj.type; //得到操作类型：add、edit、del
            var data = obj.data; //得到当前节点的数据
            var elem = obj.elem; //得到当前节点元素
            //Ajax 操作
            var id = data.id; //得到节点索引
            if (type === 'add') { //增加节点
                $("#NodeID").val(id);
                alert(id);
                index0pen = layer.open({
                    type: 1,
                    title: "新增",
                    area: ['500px', '200px'],
                    content: $("#add-node"),

                });

            } else if (type === 'update') { //修改节点
                //console.log(elem.find('.layui-tree-txt').html()); //得到修改后的内容
                $("#nodeId").val(id);
                $("#Title").val(data.title);
                index0pen = layer.open({
                    type: 1,
                    title: "编辑",
                    area: ['500px', '200px'],
                    content: $("#update-node"),

                });
            } else if (type === 'del') { //删除节点
                $.ajax({
                    url: '/Home/DelNode',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        nodeid: id
                    },
                    success: function (r) {
                        if (r > 0) {
                            layer.msg('删除成功', { icon: 6 });
                        } else {
                            layer.msg('删除失败', { icon: 5 });
                        }
                    },
                    error: function (s) {
                        layer.msg('删除出错了');
                    }
                });
            };
        }
        ,click: function(obj){
            layer.msg(JSON.stringify(obj.data));
            window.editor.getDoc().setValue("select * from new table;");
            window.editor.refresh();
        }
    });
});